//
//  MDLoginCoordinator.m
//  MvvmDemo
//
//  Created by 吴伟城 on 2018/12/16.
//  Copyright © 2018 吴伟城. All rights reserved.
//

#import "MDLoginCoordinator.h"
#import "MDLoginViewController.h"
#import "MDRegisterViewController.h"

@interface MDLoginCoordinator () <MDLoginViewControllerDelegate, MDRegisterViewControllerDelegate>

@end

@implementation MDLoginCoordinator

- (void)showLogin {
  MDLoginViewController *toVC = [[MDLoginViewController alloc] initWithDelegate:self];
  [self.navigationController pushViewController:toVC animated:NO];
}

#pragma mark - <MDLoginViewControllerDelegate>

- (void)loginViewControllerShouldShowRegisterVC:(MDLoginViewController *)loginVC {
  MDRegisterViewController *toVC = [[MDRegisterViewController alloc] initWithDelegate:self];
  [self.navigationController pushViewController:toVC animated:YES];
}

- (void)loginViewControllerShouldShowHomeVC:(MDLoginViewController *)loginVC {
  [self.navigationController popToRootViewControllerAnimated:NO];
  
  if ([self.delegate respondsToSelector:@selector(loginCoordinatorShouldShowHomeVC:)]) {
    [self.delegate loginCoordinatorShouldShowHomeVC:self];
  }
}

#pragma mark - <MDRegisterViewControllerDelegate>

- (void)registerViewControllerSucceedRegister:(MDRegisterViewController *)registerViewController {
  [self.navigationController popToRootViewControllerAnimated:NO];
  
  if ([self.delegate respondsToSelector:@selector(loginCoordinatorShouldShowHomeVC:)]) {
    [self.delegate loginCoordinatorShouldShowHomeVC:self];
  }
}

@end
